package test;

import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import dsa.LinkedList;

public class JustinWeedTest {
	
	LinkedList testList;
	
	@Before
	public void  setUp() throws Exception{		
		testList = new LinkedList();
		testList.addLast("first");
		testList.addLast("second");
		testList.addLast("third");
	}
	@Test
	public void testContains() {
		assertTrue(testList.contains("first"));
		testList.remove(0);
		assertFalse(testList.contains("first"));

	}
	@Test
	public void testGet() {
		assertTrue(testList.get(0).equals("first"));
		assertTrue(testList.get(1).equals("second"));
		assertTrue(testList.get(2).equals("third"));
		
	}
	@Test
	public void testIndexOf() {
		assertTrue(testList.indexOf("third") == 2);
		assertTrue(testList.indexOf("second") == 1);
		assertTrue(testList.indexOf("nope") == -1);

	}
	@Test
	public void testClone() {
		LinkedList clone = (LinkedList) testList.clone();
		assertTrue(testList.get(0).equals(clone.get(0)));
		assertTrue(testList.get(1).equals(clone.get(1)));
		assertTrue(testList.get(2).equals(clone.get(2)));

	}
	@Test
	public void testSize(){
		assertTrue(testList.size() == 3);
	}
	@Test
	public void testRemove(){
		assertTrue(testList.remove(0).equals("first"));
		testList.addLast("AAA");
		assertTrue(testList.removeFirst().equals("second"));
		testList.addLast("SSS");
		assertTrue(testList.removeLast().equals("SSS"));
		
	}
	@Test
	public void testToArray() {
		Object[] array = testList.toArray();
		assertTrue(array[0].equals("first"));
		assertTrue(array[1].equals("second"));
		assertTrue(array[2].equals("third"));
	}
	@Test
	public void testSet() {
		testList.set(0, "cake");
		testList.set(1, "BBB");
		assertTrue(testList.get(0).equals("cake"));
		assertTrue(testList.get(1).equals("BBB"));
	}

}
